//
//  LSUtility.h
//  LearningSystemMEE
//
//  Created by heyong on 16/3/17.
//  Copyright © 2016年 bjttsx. All rights reserved.
//
/**
 *
 */

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import "AddressModel.h"
#import "WDDAlertController.h"

@interface LSUtility : NSObject

//计算字符串的字数，
+ (int)calculateTextLength:(NSString *)text;

//动态计算字符串高度
//+ (CGSize)calculateStringSize:(NSString *)string font:(UIFont *)font constrainedSize:(CGSize)cSize;

//动态算出文本大小
+(CGSize)boundingRectWithSize:(CGSize)size font:(UIFont*)font string:(NSString*)string withSpacing:(CGFloat)spacing;

//设置文字行间距
+(NSAttributedString *)setLineSpacingWithString:(NSString *)string withFont:(CGFloat)font spacing:(CGFloat)spacing;

// 手机号部分隐藏
+ (NSString *)securePhoneNumber:(NSString *)pNum;

// 身份证号部分隐藏
+ (NSString *)secureIdCard:(NSString *)IdNum;

// toast 提示框
+ (void)showToastWithMessage:(NSString *)message inView:(UIView *)view Andtime:(CGFloat)time;

// alert提示框
+ (void)showAlertWithMessage:(NSString *)messages ok:(void (^)())ok cancel:(void (^)())cancel;
//风火轮加载
+ (void)showMBProgress:(UIView *)_targetView message:(NSString *)_msg;

//隐藏风火轮
+ (void)hideMBProgress:(UIView*)_targetView;

//隐藏风火轮没动画
+ (void)hideMBProgressNOAnimation:(UIView*)_targetView;

//判断是否是14位数字
+ (BOOL)isPureInt:(NSString*)string;


//获取当前版本号
+ (NSString *)getLocalAppVersion;

//判断网络
+ (BOOL)isConnectionAvailable;

//去掉tableview的空白处横线
+ (void)setExtraCellLineHidde:(UITableView *)tableView tabHeader:(BOOL) header tabFooter:(BOOL) footer;

//lab文字左右对其
/**
 *  设置UILable里的文字两边对齐
 *  maxInteger    : 应占字符数 （中文为1，英文为0.5/个）
 *  currentString : 要显示的文字
 */
+(void)conversionCharacterInterval:(NSInteger)maxInteger current:(NSString *)currentString withLabel:(UILabel *)label;


//计算单个文件大小
+(float)fileSizeAtPath:(NSString *)path;

//计算目录大小
+(float)folderSizeAtPath:(NSString *)path;

//清理缓存文件
+(void)clearCache:(NSString *)path;

//缓存大小
+ (NSString *)CachesSize;

//清空缓存
+ (void)cleanCaches;

//当前时间
+ (NSString *)TimeNow;

// 获取当前时间(新)
+ (NSString *)nowTime;

//时间加1分钟
+ (NSString *)nowTimeAdd1Sec;
//时间加5分钟
+ (NSString *)nowTimeAdd5Sec;
// 获取当前日期
+ (NSString *)dateNow;

//图片点击放大
+(void)imageAddTap:(UIImageView *)imageView;

//获取当前时间戳
+ (NSString *)getCurrentDateString;

//取数组前9个元素（图片
+(NSMutableArray *)imageNumNinePicture:(NSMutableArray *)array;

//保存图片到沙盒
+ (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName;

// 保存图片到沙盒(永久，不自动删除)
+ (void)saveImagePermanent:(UIImage *)currentImage withName:(NSString *)imageName;

//限制表情输入
+ (BOOL)stringContainsEmoji:(NSString *)string;

//设置图片缩略图
+ (UIImage *)thumbnailWithImage:(UIImage *)image size:(CGSize)asize;


//把格式化的JSON格式的字符串转换成字典
+ (id)dictionaryWithJsonString:(NSString *)jsonString;
+ (id)arrayWithJsonString:(NSString *)jsonString;
//首页使用
+ (id)indexDictionaryWithJsonString:(NSString *)jsonString;
//字典转字符串
+ (NSString *)dictionaryToJson:(id)dic;

// 将字典或数组转JSON
+ (NSString *)toJSONData:(id)theData;

// 将JSON串转化为字典或者数组
+ (id)toArrayOrNSMutableDictionary:(NSData *)jsonData;

/*
 *  字典转JSON_2
 */
+ (NSString*)dictionaryToJson_2:(id )dic;

+ (NSString*)dictionaryToJson_4:(id )dic;

/*
 *  字典转JSON_3
 */
+ (NSString*)dictionaryToJson_3:(id )dic;

//服务器同步附件id
+ (NSString*)dictionaryToJson_5:(id )dic;

//计算图片大小
+(NSString *)imageDataLenth:(UIImage *)image;

//获取手机ip地址
+ (NSString *)getIPAddress;

//【】() "" '的转换
+ (NSMutableString *)SymbolConversion:(NSString *)conditions;

//判断时间段
+ (BOOL)date:(NSDate*)date isBetweenDate:(NSDate*)beginDate andDate:(NSDate*)endDate;

/**
 *  是否为同一天  是否生成日记
 */
+ (BOOL)isSameDay:(NSString*)timeStr;

/**
 *  是否为同一天  是否生成日记
 */
+ (BOOL)isSameDay:(NSString*)timeStr andRecordId:(NSString *)recordId;

//监理日记是否审阅、是否是当天
+ (BOOL)isSameDayDiary:(NSString*)timeStr andTyepe:(NSString *)type;

//计算指定时间和当前时间 时间差 单位H
+(NSString *)timeDifferenceByTime:(NSString *)time;


//删除过期的图片（一天以后过期）
+(void)deleteOutofdateImageFile;

//去掉两位数前面的0
+(NSString *)deletaeZero:(NSString *)str;

//判断能否切换项目
+(BOOL)projectChangingBySignIn;

//查询配置表
+(NSDictionary *)querySystemConfig:(NSString *)name;

//根据userid查询用户信息
+(NSDictionary *)getuserIdByUserName:(NSString *)userId;

//根据登录名 查询真是姓名
+(NSDictionary *)getuserNameByRealName:(NSString *)userName;
//根据项目id 查询可否配置
+(NSString *)queryProjectExtendInfoForId:(NSString *)proId;

//根据用户名 查询userID
+(NSMutableArray *)getuserNameByUserID:(NSMutableArray *)userName;

// 根据项目ID查项目名
+ (NSDictionary *)getProjectNameByProjectId:(NSString *)projectId;

// 根据位置ID查项目位置名
+ (NSDictionary *)getAddressNameByAddressId:(NSString *)AddressId;

// 根据项目单位ID查单位名
+ (NSDictionary *)getUnitNameByUnitId:(NSString *)unitId;

// 根据项目单位ID查单位名
+ (NSDictionary *)getUnitNameByUnitIdPro:(NSString *)unitId;

//查询该项目下 总人员
+ (NSMutableArray *)queryUserByPro:(NSString *)proId;

//查询该人员的所有关联项目
+(NSMutableArray *)queryProsByUserId:(NSString *)userId;

// 根据记录id查项目记录类型
+ (NSDictionary *)getSiteTypeBySiteId:(NSString *)SiteId;

//查询人员项目下项目人员数量
+(NSMutableArray *)queryUserNumByProId:(NSString *)userId andType:(NSString *)type;

//查询人员项目下项目单位数量
+(NSMutableArray *)queryUnitNumByProId:(NSString *)userId andType:(NSString *)type;

//根据用户名 项目名查询身份
+(NSString *)getIdentityByUserId:(NSString *)userid andProId:(NSString *)proid;

//根据用户名 项目名查询所有身份
+ (NSMutableArray *)getIdentitysByUserId:(NSString *)userid andProId:(NSString *)proid andUserType:(NSString *)userType;

//根据流程id查询流程类型
+ (NSDictionary *)processTypeByprocessId:(NSString *)processId;

//查询指定表所有数据 ID 最后修改时间（传入后台作比较）
+ (NSMutableArray *)getIdAndModifyTimeFromTable:(NSString *)table;

//查询删除的数据 最后的修改时间
//+ (NSMutableArray *)getIdAndModifyTimeFromDelTable:(NSString *)table;

//根据ID和表名删除本地数据
+ (void)deleteTable:(NSString *)table andIdArr:(NSMutableArray *)idArr;

//得到项目唯一总监
+ (NSString *)directorFromProject;

//根据人员 查询该人员所属单位是否是监理单位
+ (BOOL)queryUnitIsSuperVisionbyUserID:(NSString *)userID;

//根据日记id查询身份 总监返回yes
+(BOOL)getDiaryType:(NSString *)diaryId;

//查询广告表
+ (NSMutableArray *)queryAdvertiseMent:(BOOL)isAll;

//查询施工单位
+(NSMutableArray *)constructionUnitFromProId:(NSString *)proId;

//根据附件id 查询附件信息
+(NSMutableDictionary *)queryAttachment:(NSString *)fileID;

//同步是本地无数据 入参2
+(NSMutableString *)parameterDownLoadWorkLogProIds;

// 获取项目人员数据
+ (NSMutableArray *)getProjectUser:(NSString *)flag proIds:(NSMutableArray*)proIds;

//判断项目id  本地是否存在
+ (BOOL)queryProjectForId:(NSString *)proId;

// 用""替换其他符号
+(NSMutableString *)strbydan:(NSString *)str;

/*
 *  查询巡检流程表ID 根据项目关联的巡检流程
 */
+(NSString *)queryInspectProcessIds;
//记录表新增数据
+(BOOL)insertAttachmentFromFileID:(NSString *)fileID andTableID:(NSString *)ids andImage:(UIImage *)image andType:(NSString *)type andImageName:(NSString *)imageName;

/*
 *  旁站附件批量存
 *  返回arr存入本地记录表
 */
+ (NSMutableArray *)insertAttachmentSiteFromArray:(NSMutableArray *)fileArr andRecordId:(NSString *)recordId andType:(NSString *)type andChildType:(NSString *)childType;

// 本地附件新增
+ (NSMutableArray *)insertAttachmentFromArray:(NSMutableArray *)fileArr andRecordId:(NSString *)recordId andType:(NSString *)type andRecifyState:(NSString *)recifyState;

//见证取样 存二维码到code字段
+ (NSMutableArray *)insertAttachmentFromArray:(NSMutableArray *)fileArr andRecordId:(NSString *)recordId andType:(NSString *)type andRecifyState222:(NSString *)recifyState withCodeArr:(NSMutableArray *)codeArr;

//见证取样 判断其他端口是否做了操作
+(BOOL)sampleProcessRecordIsOperationFromId:(NSString *)ProcessId;

//根据项目 和 EXTEND_INFO 查询附件id
+(NSMutableArray *)queryAttachmentFormfileId:(NSString *)fileId andExtend:(NSString *)extendInfo andFilePathArr:(NSArray *)filePathArr;

// 广告查询附件id
+(NSDictionary *)queryAdvAttachment:(NSString *)advID;

// 得到项目中 工程概览的城市
+(NSMutableDictionary *)queryProengineerSurvey:(NSString *)proId;

//查询附件
+(NSMutableArray *)quertFileImageType:(NSString *)type andId:(NSString *)recordId andFilePathArr:(NSArray *)fileArr;

//查询所有附件详情
+(NSArray *)queryAllAttachment:(NSString *)fileID;

//得到要删除的id
+(BOOL )delAttachmentForFileId:(NSString *)fileID fileName:(NSString *)imageName;

//查询该巡检流程中图片是否已经存在
+(BOOL)queryInspectProcessRFileName:(NSString *)fileName fileId:(NSString *)fileId;
// 查找图片路径
+ (NSString *)checkImagePath:(NSString *)ID;

//根据图片名称 得到图片
+(UIImage *)getImageByFileName:(NSString *)fileName;

// 根据图片名称 得到图片(如果为空,返回nil)
+(UIImage *)getImageByFileName2:(NSString *)fileName;

// 根据图片名称 得到图片地址(如果为空,返回nil)
+(NSString *)getImagePath:(NSString *)fileName;

// 得到指定时间与当前时间的时间差(小时)
+ (NSTimeInterval)getDifftimeByTime:(NSString *)endTime;

//判断是否添加日记
+ (BOOL)isExistAndType;

//监理查询当天日记是否审阅 审阅不能添加
+(BOOL)jianliQueryDiaryReView;


/**
 * 判断流程是否同步，同步后不能编辑，否则可以编辑。
 */
+(BOOL)queryProcessIsSync:(NSString *)processId;

/**
 * 判断流程记录表条数是否大于2
 */
+(BOOL)queryProcessRecordCount:(NSString *)processId;

/*
 *  二期往下写
 */



//---------  地 图  --------

//根据城市名 找到城市id
+ (NSMutableArray *)getCityIdByCityName:(NSString *)cityName;

//根据国家名 返回 id
+(NSString *)getCountryIdByCountryName:(NSString *)countryName;

//根据国家名 返回国家中心经纬度
+(NSDictionary *)getCountrylongLatByCountryName :(NSString *)countryName;


// ----------- 巡 检-------

//根据人员查到相关巡检的项目
+(NSMutableArray *)quertProIdByInspectId:(NSString *)userID;

//得到所有巡检检查类
+ (NSArray *)getInspectTimeCategory;

//查询巡检流程表记录人
+ (NSString *)getInspectUserName:(NSString *)processId;

//查询该流程下 所有的巡检项
+(NSMutableArray *)getAllItemIdByProcess:(NSString *)processId;

//根据父巡检项ID 查询巡检项
+(NSMutableArray *)getItemArrByParentID:(NSString *)parId andProcess:(NSString *)processId;

// 根据流程id 查询是否已经一键汇总完巡检任务
+(NSArray *)getTotalByProcessID:(NSString *)processId;

//  判断一键汇总是否上传
+(BOOL )getTotalByIsSync:(NSString *)processId;

//根据巡检流程记录id 查询详细记录
+(NSMutableDictionary *)queryInspectRecordById:(NSString *)recordId;

//根据巡检流程id 查询状态
+(NSString *)getInspectStateByProcessRecordId:(NSString *)prId;

//查询该流程记录是否状态4 待审核
+(BOOL )getProcessRecordState4:(NSString *)processRecordId;

//判断该任务下是否已经经过总监处理
+(BOOL )getProcessZongjianState4:(NSString *)processId;

//判断巡检流程记录该条记录是否同步 、同步后不能编辑
+(BOOL )getInspectRecordEditById:(NSString *)recordId;

//查询一键汇总表 同步后不能编辑
+(BOOL )getTotalRecordEditById:(NSString *)totalId;

//判断流程是否结束 5状态
+(NSString * )getInspectStop:(NSString *)processId;

//查询该用户巡检项状态  根据记录id
+(NSString * )getUserItemState:(NSString *)recordID;

//根据当前id查询到流程表相关联的项目id
+(NSString *)getProcessProIdByRecordID:(NSString *)recordId;

//传入当前记录id 查询该记录下指定状态下的 id
+(NSString *)queryInspectStateId:(NSString *)recordId state:(NSString *)state;

//修改巡检流程的状态
+(void)updateInspectProcessbyId:(NSString *)ids andState:(int)state;

//查询有无督办单 并且返回督办单id
+(NSString *)queryInspectSuperProcessId:(NSString *)userItemId;

//判断是否是该巡检组组长
+(BOOL)queryInspcetGroupLeader:(NSString *)gruopId;

//根据流程id 查询状态
+(NSString *)quertInspectStateByProcessId:(NSString *)processId;

//得到任务名字和创建时间
+(NSDictionary *)quertInspectProcessName:(NSString *)processId;

//判断状态进行跳转 yes跳转整改页面 显示整个流程信息 no跳转巡检页面
//+(BOOL)jumpCheckPage:(NSString *)


//修改item_user表的状态 mod
+(void)updateInspectUserItembyId:(NSString *)ids andState:(int)state;

//修改user_item的状态 add
+(void)updateInspectUserItembyIdADD:(NSString *)ids andState:(int)state;

//查询是本地新增 还是服务器返回
+(BOOL)updateIsDown:(NSString *)ids table:(NSString *)table;

//查询user_item的状态
+(NSString *)queryUserItemStateById:(NSString *)ids;


//查询最近一条状态是否是自己修改
+(BOOL)isLastInspectProcessRecord:(NSString *)userItemId;

//判断巡检项任务是否完成 。将流程表任务状态都变为5
+(void)processRecordStateExistEnd:(NSString *)processId;

//根据巡检流程 查询巡检组id（一个流程只有一个巡检组）
+(NSString *)getGroupIdByProcessId:(NSString *)processId;

//根据巡检项id 查询父级名称
+(NSMutableDictionary *)getParentNameByitemId:(NSString *)itemId;


//根据自己id 查询自己名称
+(NSMutableDictionary *)getParentNameByitemIdss:(NSString *)Id;


// 颜色转图片
+ (UIImage *)createImageWithColor:(UIColor *)color;

// 比较两个日期时间大小
+ (int)compareLocalDate:(NSString*)date01 withServerDate:(NSString*)date02;

// 返回随机颜色
+ (UIColor *)randomColor;

// 过滤掉字符串前面的n个0
+ (NSString*)getTheCorrectNum:(NSString*)tempString;

// 查找当前巡检项当前状态的条数
+ (int)getInspectItemCountByUserItemID:(NSString *)userItemID withState:(NSString *)state ;

//根据用户巡检项id 和状态返回巡检记录id
+(NSString *)quertinspectRecordStateByUserItemId:(NSString *)userItemId AndState:(NSString *)state;

// 根据二维码生成图片
+ (UIImage *)QrCodeIsGenerated:(NSString *)dataString;

// NSString单引号变双引号
+ (NSString *)stringWithString:(NSString *)jsonString;

// 获取分值上线
+ (NSString *)getInspectScore:(NSString *)inspectItemID;


#pragma mark --迭代新需求
+(void)pushNotification;
//是否打上水印
+(BOOL)isWaterMark;
//水印打印内容
+(NSArray *)queryPhotoWaterarkWord;
//是否开启推送
+(BOOL)isPushMark;
//查询推送时间
+(NSMutableDictionary *)queryPushTimeDic;
//查询推送内容
+(NSMutableDictionary *)queryPushStringDic;
+(void)pushTuisongTime:(NSString *)time str:(NSString *)str name:(NSString *)name;

//查询广告表
+ (NSMutableArray *)queryAllAdvertiseMent;

/**
 *  旁站 当前是否超过结束时间 是否被开始时间或者结束时间日记带入
 *  满足其一返回yes
 */
+ (BOOL)siteEditForendTimeAndSiteRecordId:(NSString*)siteId beginTine:(NSString *)beginTime endTime:(NSString*)endTime;

// 位置回显名称
+ (NSMutableArray *)createDataSource:(NSString *)patentID;

// 弹出WDDAlertController
+ (void)pushWDDAlertVC:(WDDAlertController *)alertVC withTitle:(NSString *)titleStr andMessageStr:(NSString *)messageStr;

//查找监理单位
+(NSMutableDictionary *)getjianliDanwei;
//获取地区天气
+(NSMutableArray *)getWeatherArea;
+(CGFloat)cellHeightWithObj:(NSString *)string Limitheight:(CGFloat)height subtractWidth:(CGFloat)width;

//根据项目角色查询人员 姓名和ID
+(NSMutableArray *)queryByType:(NSString *)type;

@end



